/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using IQIGame.Onigao.Framework;
using System.Collections.Generic;
using System.Linq;
using System;
using NetProtocol.Enum;

namespace NetProtocol.POD {

	/// <summary>
	///  主城Npc信息 -- 定时同步所有Npc坐标
	/// module : structs
	/// </summary>
	public class MainCityNpcPOD : IPOD 
    {
        public readonly static Func<MainCityNpcPOD> FACTORY = () => new MainCityNpcPOD();
		public static Func<MainCityNpcPOD> DynamicFactory = FACTORY;
        
		/*-- members --*/
		/// <summary>
        ///  唯一id
        /// </summary>
		public int id;
		/// <summary>
        ///  配置id，应该不会重复
        /// </summary>
		public int cid;
		/// <summary>
        ///  是否激活
        /// </summary>
		public bool active;
		/// <summary>
        ///  当前坐标
        /// </summary>
		public Vector3POD pos;
		/// <summary>
        /// 服务次数记录
        /// </summary>
        private Dictionary<int, int> m_serviceCount;
		
		
        public Dictionary<int, int> serviceCount
        {
            get
            {
                if(m_serviceCount == null)
                {
                    m_serviceCount = new();
                }
                return m_serviceCount;
            }
            private set => m_serviceCount = value;
        }
        public Dictionary<int, int> unsafe_serviceCount
        {
        	get => m_serviceCount;
        	set => m_serviceCount = value;
        }
		
		/*-- constructors --*/
		public MainCityNpcPOD() {}
		public MainCityNpcPOD(int id, int cid, bool active, Vector3POD pos, Dictionary<int, int> serviceCount) {
			this.id = id;
			this.cid = cid;
			this.active = active;
			this.pos = pos;
			this.m_serviceCount = serviceCount;
		}
	      public void Serial(SOutputStream _out) {
            _out.Write_int(id);
            _out.Write_int(cid);
            _out.Write_boolean(active);
            _out.Write_pod(pos);
            _out.Write_map_int_int(m_serviceCount);
        }
        
        public void UnSerial(SInputStream _in) {
            if(!_in.HasRemaining()) return;
            id = _in.Read_int();
            if(!_in.HasRemaining()) return;
            cid = _in.Read_int();
            if(!_in.HasRemaining()) return;
            active = _in.Read_boolean();
            if(!_in.HasRemaining()) return;
            pos = _in.Read_pod<Vector3POD>(Vector3POD.DynamicFactory);
            if(!_in.HasRemaining()) return;
            m_serviceCount = _in.Read_map_int_int();
        }
		
		public MainCityNpcPOD Clone() {
            MainCityNpcPOD o = DynamicFactory();
            o.id = id;
            o.cid = cid;
            o.active = active;
            if (pos != null) {
                o.pos = pos.Clone();
            }
            if (m_serviceCount != null) {
                o.m_serviceCount = new (m_serviceCount);
            }
            return o;
        }
        
        public void Clear() {
            id = default;
            cid = default;
            active = default;
            pos = default;
            m_serviceCount = default;
        }
		
        public override string ToString() {
			string str = "";
			str += "MainCityNpcPOD [";
			str += "id=";
			str += id;
			str += ", cid=";
			str += cid;
			str += ", active=";
			str += active;
			str += ", pos=";
			str += pos;
			str += ", serviceCount=";
			str += m_serviceCount.ToString<int, int>();
			str += "]";
			return str;
		}
		
	}
}